home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / FPSE_src / system / win32 / win.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-01  |  3.9 KB  |  166 lines

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <malloc.h>
  5.  
  6. #include "fpse.h"
  7. #include "win32def.h"
  8.  
  9. static FPSEWin32 FPSEWin32Info;
  10.  
  11. static char fps_en=0;
  12. char *scrpath = { "snaps\\" };
  13.  
  14. LRESULT APIENTRY WndFunc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  15. {
  16.     HDC hdc;
  17.  
  18.     switch (msg) {
  19.     case WM_KEYDOWN:
  20.         switch(wParam) {
  21.             case VK_ESCAPE:
  22.                 DestroyWindow(hwnd);
  23.                 break;
  24.             case VK_F12:
  25.                 GPU_ScreenShot(scrpath);
  26.                 break;
  27.             case VK_F11:
  28.                 fps_en ^= 1;
  29.                 break;
  30. /*
  31.             case VK_F10:
  32.                 FPSE_Flags ^= VERBOSE;
  33.                 break;
  34.             case VK_F9:
  35.                 FPSE_Flags ^= DISASMFLG;
  36.                 break;
  37. */
  38.         }
  39.         break;
  40.     case WM_PAINT:
  41.         GPU_Update();
  42.         {
  43.             PAINTSTRUCT ps;
  44.             static int t0,t1,frame,fps;
  45.             char szbuf[20];            
  46.  
  47.             hdc = BeginPaint(hwnd,&ps);
  48.  
  49.             if (fps_en) {
  50.                 if ((t1=GetTickCount()-t0)>1000) {
  51.                     fps = 1000*frame/t1;
  52.                     t0+=t1;
  53.                     frame=0;
  54.                 }
  55.                 frame++;
  56.  
  57.                 wsprintf(szbuf,"fps:%d",fps);
  58.                 TextOut(hdc,0,0,szbuf,strlen(szbuf));
  59.             }
  60.             EndPaint(hwnd,&ps);
  61.         }
  62.         break;
  63.     case WM_DESTROY:
  64.             PostQuitMessage(0);
  65.             break;
  66.         default:
  67.             return DefWindowProc(hwnd,msg,wParam,lParam);
  68.     }
  69.     return 0;
  70. }
  71.  
  72. int win_init(void)
  73. {
  74.     static char szAppName[] = "FPSE Display";
  75.     static char szClassName[] = "FPSE";
  76.     WNDCLASS wndclass;
  77.     HINSTANCE hInst = 0;
  78.  
  79.     memset(&FPSEWin32Info,0,sizeof(FPSEWin32Info));
  80.     wndclass.style = 0; //CS_HREDRAW | CS_VREDRAW;
  81.     wndclass.lpfnWndProc = WndFunc;
  82.     wndclass.cbClsExtra = 0;
  83.     wndclass.cbWndExtra = 0;
  84.     wndclass.hInstance = hInst;
  85.     wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  86.     wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
  87.     wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  88.     wndclass.lpszMenuName = NULL;
  89.     wndclass.lpszClassName = szClassName;
  90.  
  91.     RegisterClass(&wndclass);
  92.  
  93.     FPSEWin32Info.HWnd = CreateWindow(
  94.         szClassName, //classname
  95.         szAppName, //title
  96.         WS_OVERLAPPEDWINDOW,
  97.         CW_USEDEFAULT,
  98.         CW_USEDEFAULT,
  99.         320,
  100.         240,
  101.         NULL, //parent
  102.         NULL, //menu
  103.         hInst,
  104.         NULL);
  105.  
  106.     ShowWindow(FPSEWin32Info.HWnd,SW_SHOW);
  107.  
  108. // Prepare the param struct
  109.     FPSEWin32Info.SystemRam = ram;
  110.     FPSEWin32Info.HInstance = (HINSTANCE)GetWindowLong(FPSEWin32Info.HWnd,GWL_HINSTANCE);
  111.     FPSEWin32Info.ReadCfg  = INI_Read;
  112.     FPSEWin32Info.WriteCfg = INI_Write;
  113.     FPSEWin32Info.FlushRec = CompileFlush;
  114.  
  115. // Init Plug-in
  116.     if (CD_Open((UINT32*)&FPSEWin32Info)   != FPSE_OK) {
  117.         printf("CD-Rom initialization failed.\n");
  118.         return FPSE_ERR;
  119.     }
  120.     if (SPU_Open((UINT32*)&FPSEWin32Info)  != FPSE_OK) {
  121.         printf("SPU initialization failed.\n");
  122.         return FPSE_ERR;
  123.     }
  124.     if (GPU_Open((UINT32*)&FPSEWin32Info)  != FPSE_OK) {
  125.         printf("GPU initialization failed.\n");
  126.         return FPSE_ERR;
  127.     }
  128.     if (JOY0_Open((UINT32*)&FPSEWin32Info) != FPSE_OK) {
  129.         printf("Gameport 0 initialization failed.\n");
  130.         return FPSE_ERR;
  131.     }
  132.     if (JOY1_Open((UINT32*)&FPSEWin32Info) != FPSE_OK) {
  133.         printf("Gameport 1 initialization failed.\n");
  134.         return FPSE_ERR;
  135.     }
  136.  
  137.     UpdateWindow(FPSEWin32Info.HWnd);
  138.  
  139.     return FPSE_OK;
  140. }
  141.  
  142. void win_update(void)
  143. {
  144.     MSG msg;
  145.  
  146.     if (FPSEWin32Info.Flags & GPU_USE_DIB_UPDATE)
  147.         InvalidateRect(FPSEWin32Info.HWnd,NULL,FALSE);
  148.     else
  149.         GPU_Update();
  150.  
  151.     while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
  152.         if (msg.message==WM_QUIT) exit(msg.wParam);
  153.         TranslateMessage(&msg);
  154.         DispatchMessage(&msg);
  155.     }
  156. }
  157.  
  158. void win_term(void)
  159. {
  160.     GPU_Close();
  161.     SPU_Close();
  162.     JOY0_Close();
  163.     JOY1_Close();
  164.     CD_Close();
  165. }
  166.